package com.totoro.tygeneratedragonblock.data;

import org.bukkit.Chunk;
import org.bukkit.Location;

import java.util.Objects;

/**
 * @author Totoro
 * @version 0.1.0
 * @date 2025/8/11 - 13:42
 * @description 区块坐标类
 **/
public class ChunkCoordinate {
    private final String world;
    private final int x;
    private final int z;

    public ChunkCoordinate(Location location) {
        this.world = location.getWorld().getName();
        this.x = location.getBlockX() >> 4;
        this.z = location.getBlockZ() >> 4;
    }

    public ChunkCoordinate(Chunk chunk) {
        this.world = chunk.getWorld().getName();
        this.x = chunk.getX();
        this.z = chunk.getZ();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        ChunkCoordinate that = (ChunkCoordinate) o;
        return x == that.x && z == that.z && world.equals(that.world);
    }

    @Override
    public int hashCode() {
        return Objects.hash(world, x, z);
    }
}
